package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectAddDto;
import com.zzyl.dto.NursingProjectUpdateDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理项目Controller类
 */
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController {

    private final NursingProjectService nursingProjectService;

    public NursingProjectController(NursingProjectService nursingProjectService) {
        this.nursingProjectService = nursingProjectService;
    }

    @GetMapping
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "状态：0-禁用，1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        return ResponseResult.success(nursingProjectService.getByPage(name, status, pageNum, pageSize));
    }

    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult add(@RequestBody NursingProjectAddDto dto) {
        nursingProjectService.add(dto);
        return ResponseResult.success();
    }

    @GetMapping("{id}")
    @ApiOperation("根据id查询护理")
    public ResponseResult<NursingProject> getById(@PathVariable("id") Long id) {
        return ResponseResult.success(nursingProjectService.getById(id));
    }

    @PutMapping
    @ApiOperation("编辑")
    public ResponseResult<?> update(@RequestBody NursingProjectUpdateDto dto) {
        nursingProjectService.update(dto);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult<?> updateStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        nursingProjectService.updateStatus(id, status);
        return ResponseResult.success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public ResponseResult<?> delete(@PathVariable("id") Long id) {
        nursingProjectService.delete(id);
        return ResponseResult.success();
    }

    @GetMapping("/all")
    @ApiOperation("查询所有")
    public ResponseResult<List<NursingProjectVo>> getAll() {
        return ResponseResult.success(nursingProjectService.getAll());
    }

}